package com.syt.mall.coupon.config;


import com.alibaba.csp.sentinel.adapter.spring.webmvc.config.SentinelWebMvcConfig;
import com.alibaba.fastjson.JSON;
import com.syt.common.exception.BizCodeEnume;
import com.syt.common.utils.R;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SecKillSentinelConfig {

    public SecKillSentinelConfig(){
        SentinelWebMvcConfig config = new SentinelWebMvcConfig();
        config.setBlockExceptionHandler((request, response, exception) -> {
            R error = R.error(BizCodeEnume.TO_MANY_REQUEST.getCode(), BizCodeEnume.TO_MANY_REQUEST.getMsg());
            response.setCharacterEncoding("UTF-8");
            response.setContentType("application/json");
            response.getWriter().write(JSON.toJSONString(error));
        });
    }

}